import { FlyGold } from "../../core/anim/FlyGold";
import { Injectable } from "../../core/common/Decorators";
import game from "../../core/game";
import { UIBase } from "../../core/gui/UIBase";
import { Fview } from "../../core/gui/UIDefine";
import UIManage from "../../core/gui/UIManage";
import Guide from "../../core/guide/Guide";
import { GuideInfo } from "../../core/guide/GuideDefine";
import GuideManage from "../../core/guide/GuideManage";
import UI_main from "../../moduleui/main/UI_main";
import BadgeUI from "./BadgeUI";
import MainDlg from "./Maindlg";

export default class MainUI extends UIBase<UI_main> {

    public _guide_btn: Fview[];

    protected createView(): UI_main {
        return UI_main.createInstance();
    }

    protected initialize(): void {
        let view = this.view
        view.setSize(game.width, game.height);

        let btn_group = view.m_group;
        this._guide_btn = [];

        for (let i = 0, j = 0; i < view._children.length; i++) {
            let v = view.getChildAt(i);
            if (v.group === btn_group) {
                this._guide_btn.push(v.asButton);
                v.onClick(this, this.onclick, [j]);
                j++;
            }
        }
    }

    private currGuide: boolean = false;

    private onclick(stat: number) {

        if (this.currGuide) {
            return;
        }
        let ui = this.ui;

        switch (stat) {
            case 0://动画
                ui.popup(MainDlg)

                break;
            case 1://红点
                ui.popup(BadgeUI);

                break;
            case 2://本地存储

                break;
            case 3://UI交互
                ui.popQueue(BadgeUI);
                ui.popQueue(MainDlg);
                ui.popQueue(BadgeUI);
                ui.popQueue(MainDlg);
                ui.popQueue(BadgeUI);
                ui.popQueue(MainDlg);
                break;
            case 4://网络遮罩
                game.net.request("User", { uid: 1 });
                ui.showMask(true, 0, 5000);
                break;
            case 5://新手引导
                // ui.open(Guide);
                this.currGuide = true;
                let guideInfo: GuideInfo[] = [];
                for (let i = 0; i < this._guide_btn.length; i++) {
                    guideInfo.push({ view: MainUI, target: (function (index) { return this._guide_btn[index] }).bind(this, i) });
                }

                game.guide.newGuide(guideInfo, { callback: () => { this.currGuide = false; } });
                break;
            case 6://声音
                break;
            case 7://寻路
                break;
            case 8://地图
                break;

        }
    }



}